import { GNode } from './GNode';
import { Camera } from './Camera';

export class Scene extends GNode {
  private objects: GNode[] = [];

  constructor() {
    super();
  }

  add(obj: GNode): void {
    this.objects.push(obj);
    obj.setParent(this);
  }

  remove(obj: GNode): void {
    const index = this.objects.indexOf(obj);
    if (index !== -1) {
      this.objects.splice(index, 1);
      obj.setParent(null);
    }
  }

  update(deltaTime: number): void {
    super.update(deltaTime);
    this.objects.forEach(obj => obj.update(deltaTime));
  }

  render(context: CanvasRenderingContext2D, camera: Camera): void {
    this.objects.forEach(obj => obj.render(context, camera));
  }
}
